package com.service.util;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import com.bpms.common.Dict;
import com.bpms.common.VO;
import com.bpms.common.VOL;

public class DictChangeUtil {
	
	private static DictChangeUtil dcu=new DictChangeUtil();
	
	public static DictChangeUtil I(){
		return dcu;
	}
	
	public void changeListDictValue(VOL vol){
		String[] types=vol.types.split(",");
		String[] cols = vol.columns.split(",");
		for (int i = 0; i < vol.listData.size(); i++) {

			VO v = (VO) vol.listData.get(i);
			for (int j = 0; j < types.length; j++) {
//				System.out.println(type[j]+" "+col[j]+"="+v.getAttr(col[j]));
				if(!"TEXT".equals(types[j])
						&&!"PASSWORD".equals(types[j])
						&&!"TEXTAREA".equals(types[j])){
					VO d=Dict.getVO(types[j]);
					String id=v.getAttr(cols[j]);
					if(d!=null){
						String val=d.getAttr(id);
						v.setAttr(cols[j], val);
					}
				}
					
			}
		}
	}
	
	
	@SuppressWarnings("rawtypes")
	public void changeDictValue(VO vo,VO change){
		
		Set set;
		Iterator it;
		Map temp = change.attrs();
		if (temp != null) {
			set = temp.keySet();
			it = set.iterator();
			while (it.hasNext()) {
				String id =(String) it.next();
				String type = change.getAttr(id);
				String value=vo.getAttr(id);
				VO d=Dict.getVO(type);
				if(d!=null){
					String val=d.getAttr(value);
					vo.setAttr(id, val);
				}
			}
		}
	}
	
}
